home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mcomm540.zip / INT14CTS.C < prev    next >
C/C++ Source or Header  |  1991-01-06  |  4KB  |  86 lines

  1.  
  2. /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. *                                                                           *
  4. *       I N T   1 4   H O O K   T H A T   W A I T S   F O R   C T S         *
  5. *              Mike Dumdei, 6 Holly Lane, Texarkana TX 75503                *
  6. *                   Requires ASM module --> INT14HK.ASM                     *
  7. *                                                                           *
  8. *   This function sets a hook into the BIOS serial interrupt vector that    *
  9. *   waits indefinitely for CTS to go high on the specified port when send-  *
  10. *   ing data.  For the hook to have any effect when INT14 is called:        *
  11. *       1)  DX has to equal the 'portval' you set here                      *
  12. *       2)  AH has to equal '1' -- the send char service ID                 *
  13. *       3)  CTS must be FALSE                                               *
  14. *   If these conditions are all TRUE, then the hook goes into a loop        *
  15. *   until CTS goes high.  The purpose of the function is keep high speed    *
  16. *   modems that CTS handshake from creating timeout errors when redirect-   *
  17. *   ing stdout and stderr to the comm port.                                 *
  18. *                                                                           *
  19. *           To enable:  call with flag = 1                                  *
  20. *                       portval = COM1 (0) or COM2 (1)                      *
  21. *                       combase = base adrs of comm chip (ex: 3F8)          *
  22. *           To disable: call with flag = 0                                  *
  23. *                       portval = don't care                                *
  24. *                       combase = don't care                                *
  25. *                                                                           *
  26. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  27. #include <dos.h>
  28.  
  29. #if defined (__TURBOC__)
  30.   #define     _dos_getvect    getvect
  31.   #define    _dos_setvect    setvect
  32. #endif
  33.  
  34. #if defined(__ZTC__)
  35.   #include <int.h>
  36.   #define INTERRUPT
  37. #else
  38.   #include <dos.h>
  39.   #define INTERRUPT interrupt
  40. #endif
  41.  
  42. #define uint    unsigned int
  43. #define INT14   0x14                       /* BIOS serial interrupt vector */
  44.  
  45. /* these are in the ASM module */
  46. void INTERRUPT far int14ctshook(void);
  47. extern void (INTERRUPT far *oldint14)();
  48. extern uint msradr14;
  49. extern uint port14;
  50.  
  51. int ctshookset(int flag, uint portval, uint combase)
  52. {
  53.     if (flag)                                   /* enabling the INT14 hook */
  54.     {
  55.         if (msradr14 != 0)
  56.             return (-1);                       /* error if already enabled */
  57.         /* else set pointers and hook into BIOS serial port interrupt */
  58.         msradr14 = combase + 6;          /* point to modem status register */
  59.         port14 = portval;                        /* identify port affected */
  60. #if !defined (__ZTC__)
  61.         oldint14 = _dos_getvect(INT14);
  62.         _dos_setvect(INT14, int14ctshook);           /* hook INT 14 vector */
  63. #else
  64.         int_getvector(INT14, (uint *)&oldint14, (uint *)(&oldint14+2));
  65.         int_setvector(INT14, (uint)int14ctshook, *(uint *)(&int14ctshook+2));
  66. #endif
  67.         return (0);
  68.     }
  69.     else                                       /* disabling the INT14 hook */
  70.     {
  71.         if (msradr14 == 0)
  72.             return (-1);                           /* error if not enabled */
  73.         /* else set INT 14 back to original vector & reset comchip var */
  74. #if !defined (__ZTC__)
  75.         _dos_setvect(INT14, oldint14);         /* reset vector to original */
  76. #else
  77.         int_setvector(INT14, (uint)oldint14, *(uint *)(&oldint14+2));
  78. #endif
  79.         msradr14 = 0;                                  /* show not enabled */
  80.         return (0);
  81.     }
  82. }
  83.  
  84.         
  85.  
  86.